
//the encrypted  part about port
var  key = "0123456789abcedf";
var RANDOM_LENGTH = 2;

function urlWithPara(para) {
    var  encryptPara = encryptParas(para);
    var  value = '?';
    for (var key in encryptPara) {
        value = value + key + "=" + encryptPara[key] + '&';
    }
    return value;
}

function encryptParas(para) {

    var json = JSON.stringify(para).toString();
    var base64 = base64EncodeString(json);//把json对象进行64位的编码
    var string = getRandomString(RANDOM_LENGTH) + base64;//生成的密文
    var random = getRandomString(RANDOM_LENGTH);//随机字符串
    var sign = customSign(random);//本地秘钥和随机字符串进行customsign（md5加密）
    var  obj = {
        'random' : random,
        'sign'   : sign,
        'string' : string
    }
    return obj;
}

// 自定义签名
function customSign(string)
{
    return md5String(string + key).substr(0, RANDOM_LENGTH);
}

// 生成随机字符串
function getRandomString(len) {
    var random = Math.random().toString(36).substr(0, len);
    //var  random = Math.random().toString(36).slice(2, 18);
    if(random.length < len) {
        var ext = random.substr(0, len - random.length);
        random += ext;
    }
    return random;
}


//-------------------------------------------------------------
/**
 * base64 编码字符串
 * */
function base64EncodeString(string) {
    return Base64.encode(string);
}


// 获取MD5
function md5String (string) {
        return hex_md5(string);
}


